<template>
  <div class="main">
    <div class="container">
      <div class="container-top">
        <div class="top">
          <div class="title">通知</div>
        </div>
      </div>
      <ul class="container-list" v-if="noticeList.list != ''">
        <li v-for="(item, index) in noticeList.list" :key="index">
          <div class="list-main">
            <div class="main-img">
              <img src="@/assets/images/touxiang.png" alt="" />
            </div>
            <div class="main-text">
              <p class="title">{{ item.title }}</p>
              <p class="info">
                <i class="iconfont icon-yonghu"></i>
                <span>管理员</span>
                <span>{{ item.add_time | formatTime }}</span>
              </p>
            </div>
          </div>
          <div class="list-oper" @click="DetailsPage(item)">
            <i class="iconfont icon-qianwang"></i>
            <p>查看</p>
          </div>
        </li>
      </ul>
      <ul v-else class="zanwu">
        <li>暂无数据</li>
      </ul>
      <div class="block">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-count="total_page"
          :page-size="page_size"
          layout="prev, pager, next,slot"
          :total="totalAll"
        >
          <el-input v-model="page"></el-input>
          <span @click="jumperPage()">GO</span>
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import { Notice } from "@/api/login";
export default {
  name: "Notice",
  data() {
    return {
      formInline: {
        user: "",
        region: "",
        time: "",
      },
      // 当前页
      currentPage: 1,
      // 输入页码
      page: 1,
      // 总页数
      total_page: 0,
      // 每页展示个数
      page_size: 6,
      // 总条目数
      totalAll: 0,
      msg: "已读",
      noticeList: "",
      token: "",
      Showbg: true,
    };
  },
  filters: {
    formatTime(time) {
      return moment(time * 1000).format("YYYY-MM-DD");
    },
  },
  methods: {
    handleCurrentChange(val) {
      this.currentPage = val;
      this.queryNotice();
    },
    DetailsPage(item) {
      this.$router.push({
        path: "/list-details",
        query: {
          notice_id: item.notice_id,
        },
      });
    },
    jumperPage() {
      if (this.page > this.total_page) {
        this.page = this.total_page;
        alert("超过总页数");
      }
      this.currentPage = this.page - 0;
      this.queryNotice();
    },
    queryNotice() {
      Notice({
        token: this.token,
        ispage: "1",
        page_no: this.currentPage,
        page_size: this.page_size,
      }).then((result) => {
        const { data } = result;
        this.noticeList = data;
        this.totalAll = data.count - 0;
        this.total_page = Math.ceil(this.totalAll / this.page_size);
      });
    },
    backgroundShow() {
      this.$emit("backgroundShow", this.Showbg);
    },
  },
  created() {
    this.backgroundShow();
  },
  mounted() {
    const token = sessionStorage.getItem("token");
    this.token = token;
    this.queryNotice();
  },
};
</script>
<style>
/**
 * 默认尺寸为 600px×400px，如果想让图表响应尺寸变化，可以像下面这样
 * 把尺寸设为百分比值（同时请记得为容器设置尺寸）。
 */
.echarts {
  width: 100%;
  height: 100%;
}
</style>
<style lang='scss' scoped>
img{
  width: 100%;
  height: 100%;
}
.main {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 0;
  color: #242748;
  margin: 0 auto;
  position: relative;
  font-size: 18px;
  margin: 0 50px 20px 30px;
  text-align: left;
  font-family: "PingFang";
  .container {
    width: 100%;
    height: 925px;
    padding-bottom: 30px;
    background-color: #fff;
    border-radius: 10px;
    .container-top {
      .top {
        display: flex;
        .title {
          font-size: 26px;
          font-family: "黑体";
          color: #5673ff;
          margin-right: 60px;
        }
      }
      /deep/.el-badge__content.is-fixed.is-dot {
        left: 2px;
        top: 5px;
      }
      /deep/.el-form-item {
        margin-bottom: 0;
        font-size: 16px;
      }
      /deep/.el-form-item__content {
        line-height: 0;
      }
      /deep/input::placeholder {
        color: #2b3139;
        font-family: "PingFang";
      }
      /deep/.el-input__suffix {
        top: 50%;
        transform: translateY(-50%);
      }
      /deep/.el-input__inner {
        padding: 6px 15px;
        line-height: 0;
        height: auto;
        font-size: 16px;
        font-family: "PingFang";
      }
      /deep/.el-button {
        padding: 11px 20px;
        background-color: #5672ff;
        border: none;
        font-family: "PingFang";
        font-weight: 700;
      }
      /deep/.el-input__icon {
        height: auto;
      }
      /deep/.el-select .el-input .el-select__caret {
        transform: none;
      }
      /deep/.el-icon-arrow-up:before {
        content: "\e615";
        font-family: "iconfont";
        font-size: 16px;
      }
    }
    .container-top,
    .container-list li {
      padding: 33px 45px 25px;
      border-bottom: solid 1px #e7e9eb;
    }
    .container-list {
      li {
        display: flex;
        align-items: center;
        & > span {
          display: inline-block;
          padding: 7px 17px;
          margin-right: 45px;
          color: #fff;
          border-radius: 5px;
          font-size: 16px;
        }
        .purple {
          background: #bcc6fc;
        }
        .list-main {
          display: flex;
          width: 88%;
          .main-img {
            width: 65px;
            height: 65px;
            margin-right: 30px;
          }
          .main-text {
            .title {
              width: 830px;
              line-height: 35px;
              margin-bottom: 10px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              font-weight: 700;
              color: #2b3139;
            }
            .info {
              font-size: 16px;
              i {
                color: #5673ff;
                margin-right: 10px;
              }
              span {
                color: #9599a4;
                margin-right: 20px;
              }
            }
          }
        }
        .list-oper {
          text-align: center;
          color: #a1a4b5;
          cursor: pointer;
          i {
            font-size: 20px;
          }
          p {
            margin-top: 5px;
            font-size: 12px;
          }
        }
      }
    }
    .zanwu {
      li {
        text-align: center;
        margin-top: 15px;
      }
    }
    .block {
      position: absolute;
      bottom: 20px;
      left: 50%;
      transform: translateX(-50%);
      /deep/.el-input {
        width: 30px;
        height: 100%;
      }
      /deep/.el-input__inner {
        height: 25px;
        padding: 0;
        border: solid 1px #f0f1f4;
      }
      /deep/.el-pagination button,
      /deep/.el-pagination span,
      /deep/.el-pager li {
        height: 25px;
        line-height: 25px;
        color: #181b3b;
        font-weight: 700;
      }
      /deep/.el-pagination span {
        cursor: pointer;
      }
      /deep/.el-pagination.is-background .btn-next,
      /deep/.el-pagination.is-background .btn-prev,
      /deep/.el-pagination.is-background .el-pager li {
        background-color: #fff;
        border: solid 1px #f0f1f4;
        margin-right: 8px;
      }
      /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
        color: #fff;
        background-color: #5272fd;
        border: solid 1px #3957fd;
        font-size: 16px;
      }
      span {
        display: inline-block;
        width: 35px;
        height: 25px;
        line-height: 25px;
        border: solid 1px #f0f1f4;
        margin-left: 8px;
        border-radius: 2px;
      }
    }
    /deep/.el-pagination {
      text-align: center;
    }
  }
}
</style>